#!/bin/sh
# Filename: checksize
# Project: Gruvin9X Lost Model Alarm
# Original Author (this file): Christian Starkjohann
# Author: Bryan J. Rentoul (aka Gruvin)
# Creation Date: 2004-12-29
# Tabsize: 2
# Copyright: (c) 2005 OBJECTIVE DEVELOPMENT Software GmbH.
# Copyright: (c) 2014 Gruvin9X Project and Bryan J. Rentoul aka Gruvin
# Revision: $Id$
#
# This file is part of Gruvin9X Lost Model Alarm.
#
# Gruvin9X Lost Model Alarm is free software: you can redistribute it 
# and/or modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation, either version 3 of 
# the License, or(at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program in the file Lincese.txt.  If not, please
# see <http://www.gnu.org/licenses/>

error=0
codelimit=8192 
datalimit=992    # leave 32 bytes for stack

if [ $# -gt 1 ]; then
  codelimit="$2"
fi
if [ $# -gt 2 ]; then
  datalimit="$3"
fi

set -- `avr-size -d "$1" | awk '/[0-9]/ {print $1 + $2, $2 + $3, $2}'`
if [ $1 -gt $codelimit ]; then
  echo "*** code size $1 exceeds limit of $codelimit"
  error=1
else
  echo "ROM: $1 bytes (data=$3)"
fi
if [ $2 -gt $datalimit ]; then
  echo "*** data size $2 exceeds limit of $datalimit"
  error=1
else
  echo "RAM: $2 bytes"
fi

exit $error
